#include <cstdio>

const int MAX = 1000;

struct Poly {
    int exp;
    double coef;
}P[MAX+10];

double ans[2001];

int main() {
    int m, K, n, count = 0;

    scanf("%d", &K);
    for (int i = 0; i < K; i++) {
        scanf("%d%lf", &P[i].exp, &P[i].coef);
    }
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int exp;
        double coef;
        scanf("%d%lf", &exp, &coef);
        for (int i = 0; i < K; i++) {
            ans[exp+P[i].exp] += coef * P[i].coef;
        }
    }

    for (int i = 0; i <= 2000; i++) {
        if (ans[i] != 0) {
            count++;
        }
    }
    printf("%d", count);
    for (int i = 2000; i >= 0; i--) {
        if (ans[i] != 0) {
            printf(" %d %.1f", i, ans[i]);
        }
    }

    return 0;
}